;; Experiments with membrane graphics 1
;;
;; Copyright 2011:
;; James McDermott <jamesmichaelmcdermott@gmail.com>
;; Mark Wagy <mark.wagy@gmail.com>
;;
;; This file is part of p-gen, a p-systems and evolutionary system
;; written in Clojure.
;;
;; p-gen is licensed under GNU GPL v3.
;;
;; http://code.google.com/p/p-gen/

(use 'psystem.psys)
(load-file "map.clj")
(load-file "object-mappings.clj")
(load-file "turtle.clj")

(import myturtle.Turtle)

(def o+ (make-obj ['+]))
(def o- (make-obj ['-]))
(def o+1 (make-obj ['+1]))
(def o-1 (make-obj ['-1]))
(def oPUSH (make-obj ['push]))
(def oPOP (make-obj ['pop]))
(def oF (make-obj ['F]))
(def oX (make-obj ['X]))
(def oA (make-obj ['A]))
(def oRED (make-obj ['RED]))
(def oGREEN (make-obj ['GREEN]))
(def oGRAY (make-obj ['GRAY]))
(def oBLACK (make-obj ['BLACK]))
(def oORANGE (make-obj ['ORANGE]))

;;; leaves on a tree
(def r-leaves-1 (make-rule-withmove [oF] [oGRAY oF oX] 2))
(def r-leaves-2 (make-rule-withmove [oX] [oPUSH oGRAY oF oF oPUSH oGREEN o+ oX oPOP oPUSH oX oPOP oPUSH o- oX oPOP oPOP] 3))
(def r-leaves-X-to-F (make-rule [oX] [oF]))

(def m-leaves-out (make-membrane 3 [r-leaves-X-to-F] []))
(def m-leaves-2 (make-membrane 2 [r-leaves-2] [] [m-leaves-out]))
(def m-leaves-1 (make-membrane 1 [r-leaves-1] [oF] [m-leaves-2]))

(def p-leaves (make-psystem [m-leaves-1] [1 2 3]))


(def r-leaves2-1 (make-rule-withmove [oF] [oGRAY oF oX] 2))
(def r-leaves2-2 (make-rule-withmove [oX] [oPUSH oGRAY oF oF oPUSH oGREEN o+ oX oPOP oPUSH oX oPOP oPUSH o- oX oPOP oPOP] 3))

(def m-leaves2-out (make-membrane 3 [r-leaves-X-to-F] []))
(def m-leaves2-2 (make-membrane 2 [r-leaves2-2] [] [m-leaves2-out]))
(def m-leaves2-1 (make-membrane 1 [r-leaves2-1] [oF] [m-leaves2-2]))

(def p1 (make-psystem [m-leaves2-1] [1 2 3]))


;;(def c-1 (value-mapper (get-output-vals (enumerate-psystem p-1 1)) valmap-turtle-with-color))

;; example session in the REPL:
;; 
;; (init-turtle)
;; (turtle-interpret cmdz-abop-f)
;; (draw-turtle 600)
